package com.itheima.controller;

import com.itheima.resources.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.pojo.Permission;
import com.itheima.service.MenuService;
import com.itheima.service.PermissionService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/reShow")
public class ReShowController {
    @Reference
    private MenuService menuService;
    @Reference
    private PermissionService permissionService;

    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            //获取所有权限列表
            List<Permission> permissionList = permissionService.findAll();
            //获得所有菜单列表
            List<Menu> menuList = menuService.getByUsername(null);
            Map map = new HashMap();
            map.put("permissionList", permissionList);
            map.put("menuList", menuList);
            return new Result(true, MessageConstant.QUERY_POWER_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_POWER_FAIL);
        }
    }
}
